package hos.file;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;

import java.util.List;

import hos.file.media.FileType;
import hos.file.media.MediaUri;
import hos.intent.IntentCollection;
import hos.intent.IntentStart;

/**
 * <p>Title: FileStart </p>
 * <p>Description:  </p>
 * <p>Company: www.mapuni.com </p>
 *
 * @author : 蔡俊峰
 * @version : 1.0
 * @date : 2024-03-22 9:22
 */
public class FileStart {


    //<editor-fold desc="Install">

    /**
     * 获取安装APK的意图
     *
     * @param path 安装APK的URI
     */
    public static boolean launchInstallApp(Context context, final String path, int requestCode) {
        Intent intent = FileCollection.getInstallAppIntent(context, path);
        return IntentCollection.startResult(context, intent, requestCode);
    }

    /**
     * 卸载APK的意图
     *
     * @param pkgName 卸载apk的包名
     */
    public static boolean launchUninstall(Context context, final String pkgName, int requestCode) {
        Intent intent = IntentCollection.getUninstallAppIntent(pkgName);
        return IntentCollection.startResult(context, intent, requestCode);
    }

    /**
     * 获取需要启动的APK的意图
     *
     * @param context 上下文
     * @param pkgName 包名
     */
    public static boolean launchApp(Context context, final String pkgName, int requestCode) {
        Intent intent = IntentCollection.getLaunchAppIntent(context, pkgName);
        return IntentCollection.startResult(context, intent, requestCode);
    }
    //</editor-fold>

    //<editor-fold desc="OpenFile">

    public static boolean openFile(Context context, String filePath, int requestCode) {
        Intent file = FileCollection.getFile(context, filePath);
        return IntentCollection.startResult(context, file, requestCode);
    }

    public static boolean openFile(Context context, String pkgName, String filePath, int requestCode) {
        Intent file = FileCollection.getFile(context, pkgName, filePath);
        return IntentCollection.startResult(context, file, requestCode);
    }
    //</editor-fold>

    //<editor-fold desc="Media">

    /**
     * 拍照意图
     *
     * @param fileName 文件名称
     */
    public static Uri createImage(Context context, String fileName, int requestCode) {
        Uri uri = MediaUri.createImageUri(context, fileName);
        if (IntentStart.createImage(context, uri, requestCode)) {
            return uri;
        }
        return null;
    }

    /**
     * 录像意图
     *
     * @param fileName 文件名称
     */
    public static Uri createVideo(Context context, String fileName, int requestCode) {
        Uri uri = MediaUri.createVideoUri(context, fileName);
        if (IntentStart.createVideo(context, uri, requestCode)) {
            return uri;
        }
        return null;
    }

    /**
     * 录音意图
     *
     * @param fileName 文件名称
     */
    public static Uri createAudio(Context context, String fileName, int requestCode) {
        Uri uri = MediaUri.createAudioUri(context, fileName);
        if (IntentStart.createAudio(context, uri, requestCode)) {
            return uri;
        }
        return null;
    }

    /**
     * 拍照意图
     */
    public static Uri createImage(Context context, int requestCode) {
        return createImage(context, MediaUri.createImageName(), requestCode);
    }

    /**
     * 录像意图
     */
    public static Uri createVideo(Context context, int requestCode) {
        return createVideo(context, MediaUri.createVideoName(), requestCode);
    }

    /**
     * 录音意图
     */
    public static Uri createAudio(Context context, int requestCode) {
        return createAudio(context, MediaUri.createAudioName(), requestCode);
    }


    /**
     * 裁剪意图
     */
    public static boolean createCrop(Context context, String inputPath, String outputPath, int requestCode) {
        Intent intent = FileCollection.getCrop(context, inputPath, outputPath);
        return IntentCollection.startResult(context, intent, requestCode);
    }

    /**
     * 裁剪意图
     */
    public static boolean createCrop(Context context, String inputPath, String outputPath,
                                     int outputX, int outputY, int requestCode) {
        Intent intent = FileCollection.getCrop(context, inputPath, outputPath, outputX, outputY);
        return IntentCollection.startResult(context, intent, requestCode);
    }

    /**
     * 裁剪意图
     */
    public static boolean createCrop(Context context, String inputPath, String outputPath,
                                     int aspectX, int aspectY,
                                     int outputX, int outputY, int requestCode) {
        Intent intent = FileCollection.getCrop(context, inputPath, outputPath, aspectX, aspectY, outputX, outputY);
        return IntentCollection.startResult(context, intent, requestCode);
    }
    //</editor-fold>


    //<editor-fold desc="Content">

    /**
     * 选择文件
     */
    public static boolean chooseContent(Activity activity, int requestCode, FileType.Type type) {
        Intent file = FileCollection.getContentIntent(type);
        return IntentCollection.startResult(activity, file, requestCode);
    }

    /**
     * 选择文件
     *
     * @return
     */
    public static boolean chooseContentList(Activity activity, int requestCode, FileType.Type type) {
        Intent file = FileCollection.getContentListIntent(type);
        return IntentCollection.startResult(activity, file, requestCode);
    }

    /**
     * 选择文件
     */
    public static boolean chooseContentAll(Activity activity, int requestCode) {
        return chooseContent(activity, requestCode, FileType.Type.ALL);
    }

    /**
     * 选择文件
     *
     * @return
     */
    public static boolean chooseContentListAll(Activity activity, int requestCode) {
        return chooseContentList(activity, requestCode, FileType.Type.ALL);
    }
    //</editor-fold>

    //<editor-fold desc="Document">

    /**
     * 选择文件
     *
     * @return
     */
    public static boolean chooseDocument(Activity activity, int requestCode, FileType.Type... type) {
        Intent file = FileCollection.getDocumentIntent(type);
        return IntentCollection.startResult(activity, file, requestCode);
    }

    /**
     * 选择文件
     *
     * @return
     */
    public static boolean chooseDocumentList(Activity activity, int requestCode, FileType.Type... type) {
        Intent file = FileCollection.getDocumentListIntent(type);
        return IntentCollection.startResult(activity, file, requestCode);
    }

    /**
     * 选择文件
     */
    public static boolean chooseDocumentAll(Activity activity, int requestCode) {
        return chooseDocument(activity, requestCode, FileType.Type.ALL);
    }

    /**
     * 选择文件
     *
     * @return
     */
    public static boolean chooseDocumentListAll(Activity activity, int requestCode) {
        return chooseDocumentList(activity, requestCode, FileType.Type.ALL);
    }

    //</editor-fold>
    //<editor-fold desc="ImageVideo">
    public static boolean chooseImageVideo(Activity activity, int requestCode) {
        return chooseDocument(activity, requestCode, FileType.Type.IMAGE, FileType.Type.VIDEO);
    }

    /**
     * 选择文件
     */
    public static boolean chooseImageVideoDocumentList(Activity activity, int requestCode) {
        return chooseDocumentList(activity, requestCode, FileType.Type.IMAGE, FileType.Type.VIDEO);
    }
    //</editor-fold>

    //<editor-fold desc="Image">

    /**
     * 相册意图
     */
    public static boolean choosePick(Activity context, FileType.Type type, int requestCode) {
        return IntentCollection.startResult(context, FileCollection.getPickMedia(type), requestCode);
    }

    /**
     * 相册意图
     */
    public static boolean choosePickImage(Activity context, int requestCode) {
        return IntentStart.choosePickImage(context, requestCode);
    }

    public static boolean chooseImage(Activity activity, int requestCode) {
        return chooseContent(activity, requestCode, FileType.Type.IMAGE);
    }

    /**
     * 选择文件
     *
     * @return
     */
    public static boolean chooseImageList(Activity activity, int requestCode) {
        return chooseContentList(activity, requestCode, FileType.Type.IMAGE);
    }

    public static boolean chooseImageDocument(Activity activity, int requestCode) {
        return chooseDocument(activity, requestCode, FileType.Type.IMAGE);
    }

    /**
     * 选择文件
     *
     * @return
     */
    public static boolean chooseImageDocumentList(Activity activity, int requestCode) {
        return chooseDocumentList(activity, requestCode, FileType.Type.IMAGE);
    }
    //</editor-fold>

    //<editor-fold desc="Video">

    /**
     * 视频意图
     */
    public static boolean choosePickVideo(Activity context, int requestCode) {
        return IntentStart.choosePickVideo(context, requestCode);
    }

    /**
     * 视频意图
     */
    public static boolean chooseVideo(Activity activity, int requestCode) {
        return chooseContent(activity, requestCode, FileType.Type.VIDEO);
    }

    /**
     * 选择文件
     */
    public static boolean chooseVideoList(Activity activity, int requestCode) {
        return chooseContentList(activity, requestCode, FileType.Type.VIDEO);
    }

    public static boolean chooseVideoDocument(Activity activity, int requestCode) {
        return chooseDocument(activity, requestCode, FileType.Type.VIDEO);
    }

    /**
     * 选择文件
     */
    public static boolean chooseVideoDocumentList(Activity activity, int requestCode) {
        return chooseDocumentList(activity, requestCode, FileType.Type.VIDEO);
    }
    //</editor-fold>
    //<editor-fold desc="Share">

    /**
     * 分享文字
     *
     * @param content 内容
     */
    public static boolean shareTextIntent(Context context, final String content, int requestCode) {
        return IntentStart.shareTextIntent(context, content, requestCode);
    }

    /**
     * 分享图片
     *
     * @param filePath 图片地址
     */
    public static boolean shareTextImageIntent(Context context, final String filePath, int requestCode) {
        Intent intent = FileCollection.getShareTextImageIntent(context, filePath);
        return IntentCollection.startResult(context, intent, requestCode);
    }

    /**
     * 分享文字和图片
     *
     * @param content  内容
     * @param filePath 图片地址
     */
    public static boolean shareTextImageIntent(Context context, final String content,
                                               final String filePath, int requestCode) {
        Intent intent = FileCollection.getShareTextImageIntent(context, content, filePath);
        return IntentCollection.startResult(context, intent, requestCode);
    }

    /**
     * 分享文字和图片
     *
     * @param content  内容
     * @param fileList 图片地址列表
     */
    public static boolean shareTextImageIntent(Context context, final String content,
                                               final List<String> fileList, int requestCode) {
        Intent intent = FileCollection.getShareTextImageIntent(context, content, fileList);
        return IntentCollection.startResult(context, intent, requestCode);
    }
    //</editor-fold>
}
